package portal.action.rest;

/*import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;*/

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import portal.beans.Node;
//import net.sf.json.JSONObject;
import portal.cmd.JHCmd;
import portal.common.MesageCode;
import portal.common.ResultData;
import portal.conf.AbstractConf;
import portal.conf.ElimGPU;
import portal.conf.EtcHostsConf;
import portal.conf.HostGroupConf;
import portal.conf.ProcessConf;
import portal.conf.QueueConf;
import portal.mq.MQProducer;

//@Deprecated
@RequestMapping("/conf")
public class BaseAction {
	@Autowired
	QueueConf queueConf;
	@Autowired
	ElimGPU elimGPU;
	@Autowired
	EtcHostsConf etcHostsConf;
	@Autowired
	HostGroupConf hostGroupConf;
	@Autowired
	JHCmd jHCmd;
	@Autowired
	ProcessConf procConf;
	protected Logger logger = LoggerFactory.getLogger(BaseAction.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 通过Response 返回JSON数据给调用的请求
	 * */
	/*@Deprecated
	private void  responseJSON(HttpServletResponse response,ResultData ret) {
			
		 	JSONObject responseJSONObject = JSONObject.fromObject(ret);  
		    response.setCharacterEncoding("UTF-8");  
		    response.setContentType("application/json; charset=utf-8");  
		    PrintWriter out = null;  
		    try {  
		        out = response.getWriter();  
		        out.append(responseJSONObject.toString());  
		        //logger.debug("返回是\n");  
		        //logger.debug(responseJSONObject.toString());  
		    } catch (IOException e) {  
		        e.printStackTrace();  
		    } finally {  
		        if (out != null) {  
		            out.close();  
		        }  
		    }  
	}*/
	protected void println(String... str){
		//for(int i=0;i<str.length;i++)
			System.out.println(str);
	}
	protected ResultData success(){
		return success("success");
	}
	protected ResultData success(String mes){
		return new ResultData(MesageCode.SUCCESS,mes);
	}
	protected ResultData success(Object obj){
		return new ResultData(MesageCode.SUCCESS,"success",obj);
	}
	protected ResultData error(){
		return error("error");
	}
	protected ResultData error(String mes){
		return new ResultData(MesageCode.ERROR,mes);
	}
	/***
	 * 广播发送配置文件
	 * ***/
	protected final void fanoutConf(AbstractConf abc){
		MQProducer.sendMessage(abc.getFileName());
	}
	protected final void p2pNodeProcessLimit(Node node){
		MQProducer.sendMessage(node);
	}
	public BaseAction(){
		//logger.info("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
	}
}
